package com.tms.app.tms.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.amap.api.fence.GeoFence;
import com.tms.app.tms.utils.TimeUtil;

import java.util.Date;

import static com.amap.api.fence.GeoFenceClient.GEOFENCE_IN;
import static com.amap.api.fence.GeoFenceClient.GEOFENCE_OUT;

/**
 * Created by Administrator on 2018/1/13 0013.
 */

public class GeoFenceReceiver extends BroadcastReceiver {
    String stationExid,getTaskList,leave_time;
    GeoFencePresenter presenter=new GeoFencePresenter();
    //定义接收广播的action字符串
    public static final String GEOFENCE_BROADCAST_ACTION = "com.location.apis.geofencedemo.broadcast";
    @Override
    public void onReceive(Context context, Intent intent) {
        if (intent.getAction().equals(GEOFENCE_BROADCAST_ACTION)) {//解析广播内容
            //获取Bundle
            Bundle bundle = intent.getExtras();
            //获取围栏行为：
            int status = bundle.getInt(GeoFence.BUNDLE_KEY_FENCESTATUS);
            //获取自定义的围栏标识：
            String customId = bundle.getString(GeoFence.BUNDLE_KEY_CUSTOMID);
            //获取围栏ID:
            String fenceId = bundle.getString(GeoFence.BUNDLE_KEY_FENCEID);
            //获取当前有触发的围栏对象：
            GeoFence fence = bundle.getParcelable(GeoFence.BUNDLE_KEY_FENCE);
            if (customId==null||customId.length()<1)
                return;
            String sx[]=customId.split("_");
            if (sx!=null&&sx.length>1){
                stationExid=sx[1];
            }
            String time= TimeUtil.getTime(new Date(),TimeUtil.DEFAULT_DATE_FORMAT2);

            if (status==GEOFENCE_IN){
                presenter.getTaskList(stationExid,time,"-1");
            }
            if (status==GEOFENCE_OUT){
                presenter.getTaskList(stationExid,"-1",time);
            }

        }
    }
}
